// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { ccs } from "../util/services";
import { WinBase } from "./WinBase";

const {ccclass, property} = cc._decorator;
//通用弹窗
@ccclass
export default class NewClass extends WinBase {

    @property(cc.Label)
    title: cc.Label = null;

    @property(cc.RichText)
    content: cc.RichText = null;

    @property(cc.Label)
    ensureText: cc.Label = null;

    @property(cc.Label)
    cancelText: cc.Label = null;

    start () {
        this.title.string = this._args.title || "确定你的选择";
        this.content.string = this._args.content || "确定吗？";
        if(this._args.ensureText){
            this.ensureText.string = this._args.ensureText;
        }
        if(this._args.cancelText) {
            this.cancelText.string = this._args.cancelText;
        }
        
        this.touchEndEventScale(this.nodes.ensure, (res) => {
            //点击确定按钮
            if(ccs.gf.isFunction(this._args.cb)) {
                this._args.cb(res);
            }
            this._close();
        });
        this.touchEndEventScale(this.nodes.cancel, (res) => {
            //点击取消按钮
            if(ccs.gf.isFunction(this._args.cancel)) {
                this._args.cancel(res);
            }
            this._close();
        });
    }
}
